import sql_query from '@dfeidao/atom-nodejs/db/sql-query';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { spaceid, systemid } from '../../atom/config';

interface Message {
	staff_no: string;
	productid: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string[];
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin');
	// todo
	const sql = `select count(1) as size from msg_receiver mr,msg m,msg_templ_page mtp where mr.is_read=0 and m.msgid=mr.msgid and mtp.msg_type_no=m.msg_type_no and mtp.client_type='WEB'and mr.receiver_no='${message.staff_no}' and mr.productid='${message.productid}'`;

	const size = await sql_query(action_id, session_id, systemid, spaceid, sql, 'mysql');
	return {
		data: size[0]
	};
}
